package rrrmai.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

import com.jakewharton.rxbinding2.support.v7.widget.RxToolbar;
import com.jakewharton.rxbinding2.view.RxView;
import com.xgggh.rrrmai.R;
import com.xgggh.rrrmai.databinding.ActivityDetailsBinding;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import xgggh.activity.BaseActivity;

public class DetailsActivity extends BaseActivity {
    ActivityDetailsBinding mBinding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding=DataBindingUtil.setContentView(this,R.layout.activity_details);
        setSupportActionBar(mBinding.toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        mBinding.title.setText("张三(12)");
        mBinding.contentDetails.payText.setVisibility(View.GONE);

        onMenuListener();
        onListener();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_report, menu);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        return super.onPrepareOptionsMenu(menu);
    }

    private void onMenuListener(){
        RxToolbar.itemClicks(mBinding.toolbar)
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindToLifecycle())
                .subscribe(menuItem -> {
                    int itemId=menuItem.getItemId();
                    switch (itemId){
                        case R.id.action_report:
                            actionReport();
                            break;
                    }
                });
    }


    private void onListener(){
        RxView.clicks(mBinding.contentDetails.yes)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object aVoid) throws Exception {
                        Toast.makeText(DetailsActivity.this, "+1", Toast.LENGTH_SHORT).show();

                        Toast.makeText(DetailsActivity.this, "加深评论呢？", Toast.LENGTH_SHORT).show();
                    }
                });


        RxView.clicks(mBinding.contentDetails.no)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object aVoid) throws Exception {
                        Toast.makeText(DetailsActivity.this, "-1", Toast.LENGTH_SHORT).show();
                        Toast.makeText(DetailsActivity.this, "提供进一步说明呢？", Toast.LENGTH_SHORT).show();
                    }
                });


        RxView.clicks(mBinding.contentDetails.commitUserName)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object aVoid) throws Exception {
                        Intent intent = new Intent(DetailsActivity.this,UsersActivity.class);
                        startActivity(intent);
                    }
                });


        RxView.clicks(mBinding.contentDetails.commentUserName)
                .subscribe(new Consumer<Object>() {
                    @Override
                    public void accept(Object aVoid) throws Exception {
                        Intent intent = new Intent(DetailsActivity.this,PostActivity.class);
                        startActivity(intent);
                    }
                });


    }


    private void actionReport(){
        Toast.makeText(this, "report", Toast.LENGTH_SHORT).show();
    }




}
